﻿using Common.AspNetCore;
using Common.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
using StatsData.Data.Entity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace StatsData.Api.Repository
{
    /// <summary>
    /// 看板查询Repository
    /// </summary>
    public class BoardQueryRepository : CoreRepository
    {
        public BoardQueryRepository(IServiceProvider provider)
            : base(provider)
        {
        }

        /// <summary>
        /// 品质日看板获取CSI数据
        /// </summary>
        /// <param name="lineCodes"></param>
        /// <param name="beginTime"></param>
        /// <param name="endTime"></param>
        /// <param name="orgId"></param>
        /// <returns></returns>
        public async Task<List<t_csi>> GetCSIByQcBoardAsync(List<string> lineCodes, DateTime beginTime, DateTime endTime, string orgId)
        {
            if (!lineCodes.Any() == true)
            {
                return new List<t_csi>();
            }

            return await this.Repository.GetEntitiesAsync<t_csi>(new ApiParam(orgId), x => x.type == "LDX06" && lineCodes.Contains(x.line_code) && x.curr_date >= beginTime && x.curr_date < endTime);
        }
    }
}
